<template>
  <div class="dialog">
    <el-dialog
      title="仓库管理"
      :visible.sync="showDialog"
      width="65%"
      top="0"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <el-form
        ref="ruleForm"
        label-position="left"
        :model="formData"
        :rules="rules"
        class="el-form"
      >
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="仓库名称：" prop="stordocName">
              <el-input
                v-model="formData.stordocName"
                placeholder="请输入仓库名称"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="仓库位置：" prop="address">
              <el-input
                v-model="formData.address"
                placeholder="请输入仓库位置"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelbtn" @click="cancel()">取 消</el-button>
        <el-button type="primary" class="savebtn" @click="save('ruleForm')">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { deepClone } from "@/utils/index";
export default {
  name: "Addeditdialog",
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false
    },
    editData: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      formData: {},
      showDialog: this.show,
      rules: {
        stordocName: [
          {
            required: true,
            message: "请输入仓库名称",
            trigger: "blur"
          }
        ],
        address: [
          {
            required: true,
            message: "请输入仓库位置",
            trigger: "blur"
          }
        ]
      }
    };
  },

  watch: {
    show(v) {
      this.showDialog = v;
    },
    editData(v) {
      this.formData = deepClone(v);
    }
  },
  created() {},
  mounted() {
    // this.getFormData()
  },
  methods: {
    // getFormData(){
    //     this.formData = deepClone(this.editData)
    // },
    save(formData) {
      console.log(this.formData);
      this.$refs[formData].validate(valid => {
        if (valid) {
          console.log(this);
          console.log(this.formData, 111);
          this.$emit("addEvent", this.formData);
          this.close();
        }
      });
    },
    close() {
      this.$emit("closeDialog");
      this.resetForm("ruleForm");
    },
    cancel() {
      this.$emit("closeDialog");
      this.resetForm("ruleForm");
    },
    // 重置验证
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-form-item__label {
  min-width: 160px !important;
}
.pointer {
  cursor: pointer;
}
</style>
